package cn.nicklemay.interview.javabasic;


public class InnerClass
{
    private static String msg = "outter msg";

    /**
     * 静态内部类
     */
    public static class staticInnerClass
    {
         public void print()
         {
             System.out.println("From Static inner class message:" + msg);
         }
    }

    /**
     * 非静态内部类
     */
    public class NoStaticInnerClass
    {
        public void print()
        {
            System.out.println("From non-static inner class message:" + msg);
        }
    }

    public static void fun()
    {
        /**
         * 局部内部类不能被public/private/protected修饰，只能访问方法中定义为final类型的局部变量(jdk1.8以后可以不是final修饰)
         */
        String msg = "test";
        class LocalInnerClass
        {
            public void print()
            {
                System.out.println("From local inner class message:" + msg);
            }
        }
        LocalInnerClass localInnerClass = new LocalInnerClass();
        localInnerClass.print();
    }

    /**
     * 匿名内部类
     */
    abstract class AnoClass
    {
        public abstract void print();
    }

    public static void main(String args[])
    {
        InnerClass.staticInnerClass staticInnerClass = new InnerClass.staticInnerClass();

        staticInnerClass.print();

        InnerClass.NoStaticInnerClass noStaticInnerClass = new InnerClass().new NoStaticInnerClass();

        noStaticInnerClass.print();

        fun();
    }
}
